/*
 * @Date: 2025-07-21 23:23:37
 * @LastEditors: 贾二小 erxiao.jia@outlook.com
 * @LastEditTime: 2025-11-17 00:30:08
 * @FilePath: /admin-vue/src/stores/useAppStore.ts
 */
import { setLocale } from '@/locales'
import { localStg } from '@/utils/storage'
import { defineStore } from 'pinia'

export const useAppStore = defineStore('useAppStore', () => {
  const {
    bool: siderCollapse,
    setBool: setSiderCollapse,
    toggle: toggleSiderCollapse,
  } = useBoolean()

  const locale = ref<App.I18n.LangType>(localStg.get('lang') || 'zh-CN')

  const localeOptions: App.I18n.LangOption[] = [
    {
      label: '中文',
      key: 'zh-CN',
    },
    {
      label: 'English',
      key: 'en-US',
    },
  ]

  function changeLocale(lang: App.I18n.LangType) {
    locale.value = lang
    setLocale(lang)
    localStg.set('lang', lang)
  }

  return {
    siderCollapse,
    setSiderCollapse,
    toggleSiderCollapse,

    locale,
    localeOptions,
    changeLocale,
  }
})
